import { execSync } from 'child_process';

const target = process.env.BUILD_TARGET || 'default';
console.log(`开始打包，BUILD_TARGET=${target}`);

try {
  console.log('清理旧构建...');
  execSync('ts-node ./.erb/scripts/clean.js dist', { stdio: 'inherit' });

  console.log('开始构建项目...');
  execSync('npm run build', { stdio: 'inherit' });

  console.log('开始 electron-builder 打包...');
  execSync(`electron-builder --config .erb/scripts/electron-builder.config.js --publish never`, {
    stdio: 'inherit',
    env: {
      ...process.env,
      BUILD_TARGET: target,
    },
  });

  console.log('开始构建 DLL...');
  execSync('npm run build:dll', { stdio: 'inherit' });

  console.log('打包完成');
} catch (err) {
  console.error('打包失败:', err);
  process.exit(1);
}
